import time
from UI_web_A3mall.config.config import Base
from selenium.webdriver.common.by import By
from UI_web_A3mall.Tools.A3mall_db import A3mall_db

class Page3(Base):
    # 登录 /html/body/div[1]/div/div[2]/ul/li[1]/a
    login_loc = (By.XPATH,'/html/body/div[1]/div/div[2]/ul/li[1]/a')
    def login(self):
        self.click(self.login_loc)

    # 断言1 class="reg-new"
    # /html/body/div[4]/div/div[1]/div[1]/span[1]
    dy1_loc = (By.XPATH,'/html/body/div[4]/div/div[1]/div[1]/span[1]')
    def dy1(self):
        return self.text(self.dy1_loc)

    # 用户名 name="username"
    username_loc = (By.NAME,'username')
    def username(self,phone):
        self.send_keys(self.username_loc,phone)

    # 密码 name="password"
    password_loc = (By.NAME,'password')
    def password(self):
        self.send_keys(self.password_loc,'123456')

    # 验证码框架 class="c-input-text"
    yzmkj_loc = (By.CLASS_NAME,'c-input-text')
    # 验证码 //*[@id="theForm"]/div[3]/span[3]/img
    yzm_loc = (By.XPATH,'//*[@id="theForm"]/div[3]/span[3]/img')
    def yzm(self):
        self.ddddocr(self.yzm_loc,self.yzmkj_loc)

    # 登录按钮 class="finish-btn"
    dl_loc = (By.CLASS_NAME,'finish-btn')
    def dl(self):
        self.click(self.dl_loc)

    # 积分 class="color-orage"
    dy2_loc = (By.CLASS_NAME,'color-orage')
    def dy2(self):
        return self.text(self.dy2_loc)

    # class="color-black" ¥ 3970246.20
    dy3_loc = (By.CLASS_NAME,'color-black')
    def dy3(self):
        return self.text(self.dy3_loc)

    def luoji_03(self,phone):
        self.open_url('http://10.59.9.12:7001/')
        self.sql = A3mall_db(host='10.59.9.12', user='root', pwd='yidong666', database='a3mall')
        time.sleep(3)
        self.login()
        print(self.dy1())
        time.sleep(2)
        self.username(phone)
        self.password()
        self.yzm()
        time.sleep(5)
        self.dl()
        time.sleep(5)
        print(self.dy2())
        print(self.dy3())
        # print(self.dy3().replace('¥ ',''))
        dy4 = self.sql.select_sql('select * from mall_users where username = "15235688537"')
        print(dy4)